
package com.rstrulak.constant;

import org.apache.commons.lang.builder.ToStringBuilder;
public class SortField {
    /**
     * Name of a field/property to use for sorting.
     */
    private String name;

    /**
     * Order to apply to the chosen field/property sorting.
     */
    private SortInfo.SortOrder order;

    /**
     * Default constructor.
     */
    public SortField() {
    }

    /**
     * Full constructor.
     * 
     * @param name - name of a field/property to use for sorting
     * @param order - order to apply to the chosen field/property sorting
     */
    public SortField(String name, SortInfo.SortOrder order) {
        this.name = name;
        this.order = order;
    }

    public String getName() {
        return name;
    }

    public SortInfo.SortOrder getOrder() {
        return order;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setOrder(SortInfo.SortOrder order) {
        this.order = order;
    }

    /**
     * Convenience method to determine whether the order of a sort field is
     * ascending.
     * 
     * @return true for ascending order, false for descending
     */
    public boolean isOrderAscending() {
        return order == SortInfo.SortOrder.ASCENDING;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return new ToStringBuilder(this).append("name", name).append("order", order).toString();
    }
}
